{% extends "base.html" %}

{% block title %}执行员工作台 - 协同调度信息系统{% endblock %}

{% block content %}
<div class="row">
    <!-- 待执行指令 -->
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">
                    <i class="fas fa-tasks"></i> 待执行指令
                    <span class="badge bg-warning ms-2">{{ assigned_orders|length }}</span>
                </h5>
            </div>
            <div class="card-body">
                {% if assigned_orders %}
                    {% for order in assigned_orders %}
                    <div class="card mb-3 border-warning">
                        <div class="card-body">
                            <h6 class="card-title">
                                <i class="fas fa-bullhorn"></i> {{ order.target }}
                            </h6>
                            <p class="card-text">
                                <small class="text-muted">
                                    <strong>类型:</strong> 
                                    {% if order.order_type == 'reconnaissance' %}侦察指令
                                    {% elif order.order_type == 'analysis' %}分析指令
                                    {% elif order.order_type == 'execution' %}执行指令
                                    {% endif %} |
                                    <strong>优先级:</strong> 
                                    <span class="priority-badge priority-{{ order.priority }}">
                                        {% if order.priority == 'low' %}低
                                        {% elif order.priority == 'medium' %}中
                                        {% elif order.priority == 'high' %}高
                                        {% elif order.priority == 'critical' %}紧急
                                        {% endif %}
                                    </span>
                                </small>
                            </p>
                            <p class="card-text">
                                <strong>目标:</strong> {{ order.objective[:100] }}{% if order.objective|length > 100 %}...{% endif %}
                            </p>
                            <p class="card-text">
                                <strong>指令:</strong> {{ order.instructions[:100] }}{% if order.instructions|length > 100 %}...{% endif %}
                            </p>
                            <div class="d-flex justify-content-between align-items-center">
                                <small class="text-muted">
                                    {{ order.created_at.strftime('%Y-%m-%d %H:%M') }}
                                </small>
                                <a href="{{ url_for('execute_order', order_id=order.id) }}" 
                                   class="btn btn-sm btn-primary">
                                    <i class="fas fa-play"></i> 开始执行
                                </a>
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                {% else %}
                    <div class="text-center py-4">
                        <i class="fas fa-check-circle fa-2x text-success mb-2"></i>
                        <p class="text-muted mb-0">暂无待执行指令</p>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>

    <!-- 我的执行结果 -->
    <div class="col-md-6">
        <div class="card">
            <div class="card-header">
                <h5 class="mb-0">
                    <i class="fas fa-history"></i> 我的执行结果
                    <span class="badge bg-info ms-2">{{ execution_results|length }}</span>
                </h5>
            </div>
            <div class="card-body">
                {% if execution_results %}
                    {% for result in execution_results %}
                    <div class="card mb-3 border-info">
                        <div class="card-body">
                            <h6 class="card-title">
                                <i class="fas fa-check-circle"></i> 
                                {% if result.result_type == 'success' %}执行成功
                                {% elif result.result_type == 'partial' %}部分成功
                                {% elif result.result_type == 'failed' %}执行失败
                                {% endif %}
                            </h6>
                            <p class="card-text">
                                <small class="text-muted">
                                    <strong>状态:</strong> 
                                    <span class="status-badge status-{{ result.status }}">
                                        {% if result.status == 'pending' %}待审核
                                        {% elif result.status == 'reviewed' %}已审核
                                        {% endif %}
                                    </span>
                                </small>
                            </p>
                            <p class="card-text">
                                {{ result.description[:100] }}{% if result.description|length > 100 %}...{% endif %}
                            </p>
                            <div class="d-flex justify-content-between align-items-center">
                                <small class="text-muted">
                                    {{ result.created_at.strftime('%Y-%m-%d %H:%M') }}
                                </small>
                                <button class="btn btn-sm btn-outline-info" 
                                        data-bs-toggle="modal" 
                                        data-bs-target="#viewResultModal{{ result.id }}">
                                    <i class="fas fa-eye"></i> 查看详情
                                </button>
                            </div>
                        </div>
                    </div>

                    <!-- 查看执行结果详情模态框 -->
                    <div class="modal fade" id="viewResultModal{{ result.id }}" tabindex="-1">
                        <div class="modal-dialog modal-lg">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title">执行结果详情</h5>
                                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                                </div>
                                <div class="modal-body">
                                    <div class="row mb-3">
                                        <div class="col-md-6">
                                            <p><strong>执行结果:</strong> 
                                                {% if result.result_type == 'success' %}执行成功
                                                {% elif result.result_type == 'partial' %}部分成功
                                                {% elif result.result_type == 'failed' %}执行失败
                                                {% endif %}
                                            </p>
                                        </div>
                                        <div class="col-md-6">
                                            <p><strong>状态:</strong> 
                                                <span class="status-badge status-{{ result.status }}">
                                                    {% if result.status == 'pending' %}待审核
                                                    {% elif result.status == 'reviewed' %}已审核
                                                    {% endif %}
                                                </span>
                                            </p>
                                        </div>
                                    </div>
                                    
                                    <h6>执行描述:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.description }}</pre>
                                    </div>
                                    
                                    {% if result.evidence %}
                                    <h6>执行证据:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.evidence }}</pre>
                                    </div>
                                    {% endif %}
                                    
                                    {% if result.impact_assessment %}
                                    <h6>影响评估:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.impact_assessment }}</pre>
                                    </div>
                                    {% endif %}
                                    
                                    {% if result.lessons_learned %}
                                    <h6>经验教训:</h6>
                                    <div class="bg-light p-3 rounded mb-3">
                                        <pre style="white-space: pre-wrap; margin: 0;">{{ result.lessons_learned }}</pre>
                                    </div>
                                    {% endif %}
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    {% endfor %}
                {% else %}
                    <div class="text-center py-4">
                        <i class="fas fa-history fa-2x text-muted mb-2"></i>
                        <p class="text-muted mb-0">暂无执行结果</p>
                    </div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<!-- 执行统计 -->
<div class="row mt-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">
                    <i class="fas fa-chart-bar"></i> 执行统计
                </h6>
            </div>
            <div class="card-body">
                <div class="row text-center">
                    <div class="col-md-3">
                        <div class="mb-3">
                            <i class="fas fa-tasks fa-2x text-warning mb-2"></i>
                            <h4 class="text-warning">{{ assigned_orders|length }}</h4>
                            <h6>待执行指令</h6>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="mb-3">
                            <i class="fas fa-check-circle fa-2x text-success mb-2"></i>
                            <h4 class="text-success">
                                {{ execution_results|selectattr('result_type', 'equalto', 'success')|list|length }}
                            </h4>
                            <h6>成功执行</h6>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="mb-3">
                            <i class="fas fa-exclamation-triangle fa-2x text-warning mb-2"></i>
                            <h4 class="text-warning">
                                {{ execution_results|selectattr('result_type', 'equalto', 'partial')|list|length }}
                            </h4>
                            <h6>部分成功</h6>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="mb-3">
                            <i class="fas fa-times-circle fa-2x text-danger mb-2"></i>
                            <h4 class="text-danger">
                                {{ execution_results|selectattr('result_type', 'equalto', 'failed')|list|length }}
                            </h4>
                            <h6>执行失败</h6>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 工作流程说明 -->
<div class="row mt-4">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0">
                    <i class="fas fa-info-circle"></i> 执行员工作流程
                </h6>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-3 text-center">
                        <div class="mb-3">
                            <i class="fas fa-bullhorn fa-2x text-primary mb-2"></i>
                            <h6>接收指令</h6>
                            <small class="text-muted">接收决策员下达的执行指令</small>
                        </div>
                    </div>
                    <div class="col-md-3 text-center">
                        <div class="mb-3">
                            <i class="fas fa-cogs fa-2x text-info mb-2"></i>
                            <h6>执行任务</h6>
                            <small class="text-muted">按照指令要求执行具体任务</small>
                        </div>
                    </div>
                    <div class="col-md-3 text-center">
                        <div class="mb-3">
                            <i class="fas fa-clipboard-check fa-2x text-warning mb-2"></i>
                            <h6>记录结果</h6>
                            <small class="text-muted">详细记录执行过程和结果</small>
                        </div>
                    </div>
                    <div class="col-md-3 text-center">
                        <div class="mb-3">
                            <i class="fas fa-paper-plane fa-2x text-success mb-2"></i>
                            <h6>提交反馈</h6>
                            <small class="text-muted">将执行结果反馈给决策员</small>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
